package com.micl.fileserver.utils;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;

@Component
public class FileUtil {

    @Value(value = "${micl.upload.file.path.temp}")
    private String decryptFilePath;
    @Value(value = "${micl.upload.file.path}")
    private String mergeFilePath;

    public File getUUIDFile(){
        File files[] = new File(decryptFilePath).listFiles();

        Arrays.sort(files, new Comparator<File>() {
            public int compare(File f1, File f2) {
                long diff = f1.lastModified() - f2.lastModified();
                if (diff > 0)
                    return -1;
                else if (diff == 0)
                    return 0;
                else
                    return 1;//如果 if 中修改为 返回-1 同时此处修改为返回 1  排序就会是递减
            }

            public boolean equals(Object obj) {
                return true;
            }

        });

        return Objects.requireNonNull(new File(decryptFilePath).listFiles())[0];
    }

}
